package com.nageoffer.shortlink.admin.controller;

import com.nageoffer.shortlink.admin.common.convention.exception.ServiceException;
import com.nageoffer.shortlink.admin.common.convention.result.Result;
import com.nageoffer.shortlink.admin.common.convention.result.Results;
import com.nageoffer.shortlink.admin.dto.req.GroupSaveRequestDTO;
import com.nageoffer.shortlink.admin.dto.req.GroupSortUpdateRequestDTO;
import com.nageoffer.shortlink.admin.dto.resp.GroupListRespDTO;
import com.nageoffer.shortlink.admin.service.GroupService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 刘新智
 * @Date: 2025/10/20 19:11
 * @Description: 短链接分组控制层
 * @Version: v1.0
 */
@RestController
@RequestMapping("api/shortlink/admin/v1/group")
@AllArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * @description: 新增短链接分组
     * @author: 刘新智
     * @date: 2025/10/20 20:06
     * @param: [groupSaveRequestDTO]
     * @return: com.nageoffer.shortlink.admin.common.convention.result.Result<java.lang.Void>
     **/
    @PostMapping("/save")
    public Result<Void> save(@RequestBody GroupSaveRequestDTO groupSaveRequestDTO) throws ServiceException {
        groupService.save(groupSaveRequestDTO);
        return Results.success();
    }


    /**
     * @description: 获取短链接分组列表
     * @author: 刘新智
     * @date: 2025/10/21 10:25
     * @param: []
     * @return: com.nageoffer.shortlink.admin.common.convention.result.Result<java.util.List<com.nageoffer.shortlink.admin.dto.resp.GroupListRespDTO>>
     **/
    @PostMapping("/list")
    public Result<List<GroupListRespDTO>> groupList() {
        List<GroupListRespDTO> groupList = groupService.groupList();
        return Results.success(groupList);
    }

    /**
     * @description: 删除短链接分组
     * @author: 刘新智
     * @date: 2025/10/21 10:45
     * @param: [gid]
     * @return: com.nageoffer.shortlink.admin.common.convention.result.Result<java.lang.Void>
     **/
    @PostMapping("/delete")
    public Result<Void> delete(@RequestParam String gid) {
        groupService.delete(gid);
        return Results.success();
    }

    /**
     * @description: 更新短链接分组排序
     * @author: 刘新智
     * @date: 2025/10/21 10:46
     * @param: [groupSortUpdateRequestDTOList]
     * @return: com.nageoffer.shortlink.admin.common.convention.result.Result<java.lang.Void>
     **/
    @PostMapping("/updateSort")
    public Result<Void> updateSort(@RequestBody List<GroupSortUpdateRequestDTO> groupSortUpdateRequestDTOList) {
        groupService.updateSort(groupSortUpdateRequestDTOList);
        return Results.success();
    }
}
